package org.blogwu.learn.multithread.chapter2.demo3;

public class WaitTest {

    public static void main(String[] args) {
        WaitMe waitMe = new WaitMe();
        waitMe.start();
        System.out.println("Main start wait me ");
        waitMe.waitMe();
        System.out.println("Main start wait me end ");
    }
}


class WaitMe extends Thread {

    public static final Object object = new Object();


    public synchronized void waitMe() {
        System.out.println(Thread.currentThread() + " wait start");
        try {
            wait(0);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread() + " wait over");
    }

    @Override
    public void run() {
        int i = 0;
        while (true) {
            System.out.println(Thread.currentThread() + " add one: " + i);
            i++;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (i == 10) {
                synchronized (this) {
                    notify();
                }
            }
        }
    }
}
